//
//  ACCreateLiveRightArrowCell.m
//  ACLiteAVUISDK
//
//  Created by 冯琰琰 on 2021/3/30.
//

#import "ACCreateLiveInfoCell.h"

@interface ACCreateLiveInfoCell ()
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIButton *uploadBtn;
@property (weak, nonatomic) IBOutlet UIButton *rightArrowBtn;
@property (weak, nonatomic) IBOutlet UISwitch *switchBtn;
@property (weak, nonatomic) IBOutlet UITextField *detailInfo;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *DetailInfoTopLayout;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *DetailInfoBottomLayout;


@end


@implementation ACCreateLiveInfoCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.uploadBtn.layer.masksToBounds = YES;
    self.uploadBtn.layer.cornerRadius = 16;
    
    [self.uploadBtn setHidden:YES];
    [self.switchBtn setHidden:YES];
    [self.rightArrowBtn setHidden:YES];
    @weakify(self);
    [[self.switchBtn rac_signalForControlEvents:UIControlEventValueChanged] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self)
        if (self.switchValueChangeHandler) {
            self.switchValueChangeHandler(self.switchBtn.on);
        }
    }];
    
    [[self.uploadBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self)
        if (self.uploadClickHandler) {
            self.uploadClickHandler();
        }
    }];
    [[self.detailInfo rac_signalForControlEvents:UIControlEventEditingDidEnd] subscribeNext:^(__kindof UIControl * _Nullable x) {
        DDLogInfo(@"%@",x);
        @strongify(self)
        if (self.textEditEndHandler) {
            self.textEditEndHandler(self.detailInfo.text);
        }
    }];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
}
-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    
    NSString *titleStr = [_dataDic valueForKey:@"title"];
    self.titleLabel.text = titleStr;
    
    NSString *infoStr = [_dataDic valueForKey:@"Info"];
    self.detailInfo.text = infoStr;
    
    NSString *plceHolder = [_dataDic valueForKey:@"placeHolder"];
    self.detailInfo.placeholder = plceHolder;
    
    // rightType   0 空白  1 箭头 2 上传按钮  3 switch
    // action  1 编辑  2跳转页面 3时间选择器  4上传按钮  5 switch
    NSInteger rightType = [[_dataDic valueForKey:@"rightType"] integerValue];
    switch (rightType) {
        case 0:
        {
            [self.uploadBtn setHidden:YES];
            [self.switchBtn setHidden:YES];
            [self.rightArrowBtn setHidden:YES];
            self.DetailInfoTopLayout.constant = 34;
            self.DetailInfoBottomLayout.constant = 10;
        }
            break;
        case 1:
        {
            [self.uploadBtn setHidden:YES];
            [self.switchBtn setHidden:YES];
            [self.rightArrowBtn setHidden:NO];
            self.DetailInfoTopLayout.constant = 34;
            self.DetailInfoBottomLayout.constant = 10;
        }
            break;
        case 2:
        {
            [self.uploadBtn setHidden:NO];
            [self.switchBtn setHidden:YES];
            [self.rightArrowBtn setHidden:YES];
            self.titleLabel.text = @"";
            self.detailInfo.text = titleStr;
            self.DetailInfoTopLayout.constant = 22;
            self.DetailInfoBottomLayout.constant = 22;
        }
            break;
        case 3:
        {
            [self.uploadBtn setHidden:YES];
            [self.switchBtn setHidden:NO];
            [self.switchBtn setOn:[infoStr boolValue]];
            [self.rightArrowBtn setHidden:YES];
            self.titleLabel.text = @"";
            self.detailInfo.text = titleStr;
            self.DetailInfoTopLayout.constant = 22;
            self.DetailInfoBottomLayout.constant = 22;
        }
            break;
        default:
            break;
    }
    NSInteger actionType = [[_dataDic valueForKey:@"action"] integerValue];
    if (actionType == 1) {
        [self.detailInfo setEnabled:YES];
    }else{
        [self.detailInfo setEnabled:NO];
    }
}
@end
